package com.jiehoo.elove.dao;

import java.lang.reflect.Proxy;

import com.jiehoo.elove.dao.jdo.RobotJDO;

public class DAOFactory {
	private static RobotDAO robotDAO;
	static
	{
		init();
	}

	private static void init() {
		try {
			robotDAO = initDAO(RobotDAO.class, RobotJDO.class);
		} catch (Exception e) {
			throw new RuntimeException("Can not init DAO.",e);
		}
	}

	private static <T> T initDAO(Class<T> daoInterface, Class<?> implementClass)
			throws IllegalArgumentException, InstantiationException,
			IllegalAccessException {
		return (T) Proxy.newProxyInstance(daoInterface.getClassLoader(),
				new Class[] { daoInterface }, new EnhanceHanlder(implementClass
						.newInstance()));
	}

	public static RobotDAO getRobotDAO() {
		return robotDAO;
	}
	
}
